ALTER FUNCTION
ALTER FUNCTION — Change the Definition of a Function
Synopsis
ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
action [ ... ] [ RESTRICT ]
ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
RENAME TO new_name
ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
SET SCHEMA new_schema
ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
[ NO ] DEPENDS ON EXTENSION extension_name
where action is one of:
CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
IMMUTABLE | STABLE | VOLATILE | [ NOT ] LEAKPROOF
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
PARALLEL { UNSAFE | RESTRICTED | SAFE }
COST execution_cost
ROWS result_rows
SUPPORT support_function
SET configuration_parameter { TO | = } { value | DEFAULT }
SET configuration_parameter FROM CURRENT
RESET configuration_parameter
RESET ALL
Description
ALTER FUNCTION changes the definition of a function.
You must own the function to use ALTER FUNCTION. To change the schema of a function, you must also have CREATE privilege on the new schema. To change the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the function's schema (these restrictions enforce that changing the owner cannot do anything you couldn't do by dropping and recreating the function. However, a superuser can change ownership of any function).
Parameters
name
The name (optionally schema-qualified) of an existing function. If no argument list is specified, the name must be unique in its schema.
argmode
The mode of an argument: IN, OUT, INOUT, or VARIADIC. If omitted, the default is IN. Note that ALTER FUNCTION does not actually care about OUT arguments, since only input arguments are needed to determine the function's identity. Therefore, listing IN, INOUT, and VARIADIC arguments is sufficient.
argname
The name of an argument. Note that ALTER FUNCTION does not actually care about argument names, since only the argument data types are needed to determine the function's identity.
argtype
The data type(s) of the function's arguments (if any), optionally schema-qualified.
new_name
The new name of the function.
new_owner
The new owner of the function. Note that if the function is marked as SECURITY DEFINER, subsequent executions will use the new owner.
new_schema
The new schema for the function.
DEPENDS ON EXTENSION extension_name
NO DEPENDS ON EXTENSION extension_name
This form marks the function as dependent on the extension, or if NO is specified, no longer dependent on that extension. Functions marked as dependent on an extension are automatically dropped when the extension is dropped.
CALLED ON NULL INPUT
RETURNS NULL ON NULL INPUT
STRICT
CALLED ON NULL INPUT changes the function so that it can be called when some or all of its arguments are null.
RETURNS NULL ON NULL INPUT or STRICT changes the function so that it is not called when any of its arguments are null; instead, a null result is assumed automatically. See CREATE FUNCTION for details.
IMMUTABLE
STABLE
VOLATILE
Changes the volatility of the function to the specified setting. See CREATE FUNCTION for details.
[ EXTERNAL ] SECURITY INVOKER
[ EXTERNAL ] SECURITY DEFINER
Changes whether the function is a security definer. The keyword EXTERNAL is ignored for SQL conformance. See CREATE FUNCTION for details on this capability.
PARALLEL
Determines whether the function is safe for parallelism. See CREATE FUNCTION for details.
LEAKPROOF
Changes whether the function is considered leakproof. See CREATE FUNCTION for details on this capability.
COST execution_cost
Changes the estimated execution cost of the function. See CREATE FUNCTION for details.
ROWS result_rows
Changes the estimated number of rows returned by a set-returning function. See CREATE FUNCTION for details.
SUPPORT support_function
Sets or changes the planner support function to use for this function. You must be a superuser to use this option.
This option cannot be used to completely remove the support function, as it must name a new support function. If you need to do this, use CREATE OR REPLACE FUNCTION.
configuration_parameter
value
Adds or changes an assignment to be made to a configuration parameter when the function is called. If value is DEFAULT, or the equivalent RESET is used, the function-local setting is removed, so the function will execute with the value present in its environment. Use RESET ALL to clear all function-local settings. SET FROM CURRENT saves the current value of the parameter when ALTER FUNCTION is executed as the value to apply when entering the function.
RESTRICT
Present for SQL standard conformance; ignored.
Examples
# To rename the function sqrt for type integer to square_root:
ALTER FUNCTION sqrt(integer) RENAME TO square_root;
# To change the owner of the function sqrt for type integer to joe:
ALTER FUNCTION sqrt(integer) OWNER TO joe;
# To change the schema of the function sqrt for type integer to maths:
ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
# To mark the function sqrt for type integer as dependent on extension mathlib:
ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
# To adjust the automatic search path of a function:
ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
# To disable the automatic setting of search_path for a function:
ALTER FUNCTION check_password(text) RESET search_path;
# This function will now execute with the search path used by its caller.